package com.tech.koufu.ui.view;

 
import com.tech.koufu.R;    
import com.tech.koufu.ui.adapter.MarketAdapter; 
import extras.com.handmark.pulltorefresh.library.PullToRefreshBase;  
import extras.com.handmark.pulltorefresh.library.PullToRefreshGridView;  
import extras.com.handmark.pulltorefresh.library.PullToRefreshBase.Mode;
import extras.com.handmark.pulltorefresh.library.PullToRefreshBase.OnRefreshListener2; 
import android.os.Bundle;
import android.support.annotation.Nullable; 
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup; 
import android.widget.GridView; 

/**
 * 行情 fragment
 * 
 * @author jl_luo
 * 
 */
public class MarketContentFragment extends BaseContainerFragment implements OnClickListener{
	private static final String TAG = MarketContentFragment.class.getName();
	
	private View rootView;
	private PullToRefreshGridView mPullToRefreshGridView;
	private GridView actualListView;
	private MarketAdapter mAdapter;
	
 
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
	}

	@Override
	public View onCreateView(LayoutInflater inflater,
			@Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { 
		if (rootView == null) {Log.d(TAG, "~~~~~MarketContentFragment~onCreateView~~~~~~~~~~");
			rootView = inflater.inflate(R.layout.activity_main_market, container, false);
			initView();
			initData();
		}else{
			Log.d(TAG, "~~~~no~MarketContentFragment~onCreateView~~~~~~~~~~");
		}
		ViewGroup parent = (ViewGroup) rootView.getParent();
		if (parent != null) {
			parent.removeView(rootView);
		}
	
		return rootView; 
	}

	private void initView() {  
		mPullToRefreshGridView = (PullToRefreshGridView) rootView.findViewById(R.id.pull_refresh_grid);
		mPullToRefreshGridView.setOnRefreshListener(new OnRefreshListener2() {

			@Override
			public void onPullDownToRefresh(PullToRefreshBase refreshView) { 
				mPullToRefreshGridView.onRefreshComplete();
			}

			@Override
			public void onPullUpToRefresh(PullToRefreshBase refreshView) { 
				mPullToRefreshGridView.onRefreshComplete();
			}
		});

		actualListView = mPullToRefreshGridView.getRefreshableView(); 
	}

	@Override
	public void onActivityCreated(@Nullable Bundle savedInstanceState) {
		super.onActivityCreated(savedInstanceState); 
//		initData();
	}

	private void initData() { 
		mAdapter = new MarketAdapter(getActivity().getApplicationContext());
		actualListView.setAdapter(mAdapter);
	}

	@Override
	public void onClick(View v) { 
		switch (v.getId()) {
		 

		default:
			break;
		}
	}
 
	 
	 
}
